package com.authsphere.security.account.common.config;

import java.util.Optional;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/25 16:23
 **/
public class SecurityAccountConfig {

    private LockAccountConfig lockAccountConfig;

    private BindAccountConfig bindAccountConfig;


    public LockAccountConfig getLockAccountConfig() {
        return Optional.ofNullable(lockAccountConfig).orElseGet(LockAccountConfig::new);
    }

    public void setLockAccountConfig(LockAccountConfig lockAccountConfig) {
        this.lockAccountConfig = lockAccountConfig;
    }

    public BindAccountConfig getBindAccountConfig() {
        return bindAccountConfig;
    }

    public void setBindAccountConfig(BindAccountConfig bindAccountConfig) {
        this.bindAccountConfig = bindAccountConfig;
    }

    public static class LockAccountConfig {

        /**
         * 最大尝试次数
         */
        private int[] maxAttempts;

        /**
         * 锁定时间
         */
        private int[] lockForMinutes;

        /**
         * 锁定间隔时间
         */
        private int lockIntervalTime = 3600;

        /**
         * 锁定前缀
         */
        private String lockPrefix = "authsphere:lockedAccount:";

        public LockAccountConfig() {
            this.maxAttempts = new int[]{5, 10, 15};
            this.lockForMinutes = new int[]{5, 30, -1};
        }

        public int[] getMaxAttempts() {
            return maxAttempts;
        }

        public void setMaxAttempts(int[] maxAttempts) {
            this.maxAttempts = maxAttempts;
        }

        public int[] getLockForMinutes() {
            return lockForMinutes;
        }

        public void setLockForMinutes(int[] lockForMinutes) {
            this.lockForMinutes = lockForMinutes;
        }

        public int getLockIntervalTime() {
            return lockIntervalTime;
        }

        public void setLockIntervalTime(int lockIntervalTime) {
            this.lockIntervalTime = lockIntervalTime;
        }

        public String getLockPrefix() {
            return lockPrefix;
        }

        public void setLockPrefix(String lockPrefix) {
            this.lockPrefix = lockPrefix;
        }

        public void check() {
            if (maxAttempts.length != lockForMinutes.length) {
                throw new IllegalArgumentException("maxAttempts.length != lockForMinutes.length");
            }
        }
    }

    public static class BindAccountConfig {

        private String tokenParameter = "bindToken";

        private String redirectUrlParameter = "redirectUrl";

        private String timestampParameter = "timestamp";

        private int timeout = 300;

        private String tokenPrefix = "";

        /**
         * token过期时间，单位：秒
         * 默认300秒
         */
        private int tokenExpireTime = 300;

        /**
         * token长度
         */
        private int tokenLength = 16;

        public String getTokenPrefix() {
            return tokenPrefix;
        }

        public void setTokenPrefix(String tokenPrefix) {
            this.tokenPrefix = tokenPrefix;
        }

        public int getTokenExpireTime() {
            return tokenExpireTime;
        }

        public void setTokenExpireTime(int tokenExpireTime) {
            this.tokenExpireTime = tokenExpireTime;
        }

        public int getTokenLength() {
            return tokenLength;
        }

        public void setTokenLength(int tokenLength) {
            this.tokenLength = tokenLength;
        }

        public String getTokenParameter() {
            return tokenParameter;
        }

        public void setTokenParameter(String tokenParameter) {
            this.tokenParameter = tokenParameter;
        }

        public String getRedirectUrlParameter() {
            return redirectUrlParameter;
        }

        public void setRedirectUrlParameter(String redirectUrlParameter) {
            this.redirectUrlParameter = redirectUrlParameter;
        }

        public String getTimestampParameter() {
            return timestampParameter;
        }

        public void setTimestampParameter(String timestampParameter) {
            this.timestampParameter = timestampParameter;
        }

        public int getTimeout() {
            return timeout;
        }

        public void setTimeout(int timeout) {
            this.timeout = timeout;
        }


    }
}
